﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Housing;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ////This login code has some bug,('or 'a'='a) 
       
    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        
        bool isLogin = false;
        if (Session["CheckCode"] != null)
        {
            
            if (txbcheck.Text == Session["CheckCode"].ToString())
            {
                Users user = new Users();
                user.GetUserByUserName(txbusername.Text);
                if (txbpwd.Text == user.Password)
                {
                    Session["UserId"] = user.UserId;
                    Session["UserName"] = txbusername.Text;
                    Session["UserType"] = user.UserType;
                    Session["UserStreet"] = user.UserStreet;
                    isLogin = true;
                }
                if (isLogin)
                {
                    if (Session["UserType"].ToString() == "住房保障管理中心")
                        Response.Redirect("ManageCenter/Index.aspx");
                    else if (Session["UserType"].ToString() == "民政部门")
                        Response.Redirect("GovDepartment/Index.aspx");
                    else if (Session["UserType"].ToString() == "辖区房管所")
                        Response.Redirect("HouseKeep/ManageAdmissibility.aspx");
                    else
                        Response.Redirect("StreetCenter/ManageAdmissibility.aspx");
                }
                else
                    WebHelper.Alert("用户名或密码错误！");
            }
            else
                WebHelper.Alert("验证码错误！");
        }
        else
        {
            WebHelper.AlertAndRefresh("验证码过期，请重新登陆");
        }
    }
    protected void btnclear_Click(object sender, EventArgs e)
    {
        txbusername.Text = "";
        txbpwd.Text = "";
        txbcheck.Text = "";
    }
}
